package service

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
)

//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateCoopComTwo
//@description: 创建CoopComTwo记录
//@param: coopComTwo model.CoopComTwo
//@return: err error

func CreateCoopComTwo(coopComTwo model.CoopComTwo) (err error) {
	err = global.GVA_DB.Create(&coopComTwo).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteCoopComTwo
//@description: 删除CoopComTwo记录
//@param: coopComTwo model.CoopComTwo
//@return: err error

func DeleteCoopComTwo(coopComTwo model.CoopComTwo) (err error) {
	err = global.GVA_DB.Delete(&coopComTwo).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteCoopComTwoByIds
//@description: 批量删除CoopComTwo记录
//@param: ids request.IdsReq
//@return: err error

func DeleteCoopComTwoByIds(ids request.IdsReq) (err error) {
	err = global.GVA_DB.Delete(&[]model.CoopComTwo{},"id in ?",ids.Ids).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateCoopComTwo
//@description: 更新CoopComTwo记录
//@param: coopComTwo *model.CoopComTwo
//@return: err error

func UpdateCoopComTwo(coopComTwo model.CoopComTwo) (err error) {
	err = global.GVA_DB.Save(&coopComTwo).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetCoopComTwo
//@description: 根据id获取CoopComTwo记录
//@param: id uint
//@return: err error, coopComTwo model.CoopComTwo

func GetCoopComTwo(id uint) (err error, coopComTwo model.CoopComTwo) {
	err = global.GVA_DB.Where("id = ?", id).First(&coopComTwo).Error
	return
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetCoopComTwoInfoList
//@description: 分页获取CoopComTwo记录
//@param: info request.CoopComTwoSearch
//@return: err error, list interface{}, total int64

func GetCoopComTwoInfoList(info request.CoopComTwoSearch) (err error, list interface{}, total int64) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&model.CoopComTwo{})
    var coopComTwos []model.CoopComTwo
    // 如果有条件搜索 下方会自动创建搜索语句
    if info.Name != "" {
        db = db.Where("`name` LIKE ?","%"+ info.Name+"%")
    }
	err = db.Count(&total).Error
	err = db.Limit(limit).Offset(offset).Find(&coopComTwos).Error
	return err, coopComTwos, total
}